Skip to content

chore(spanner): validate positional parameter count in StatementFactory.withUnnamedParameters - #15072

Open
sakthivelmanii wants to merge 1 commit into
mainfrom
validate-statement-factory-unnamed-parameters
Open

sakthivelmanii wants to merge 1 commit into
mainfrom
validate-statement-factory-unnamed-parameters

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem

  • Statement.StatementFactory.withUnnamedParameters(String, Object...) did not validate that the number of provided parameter values matched the number of positional ? placeholders in the SQL string, allowing extra values to be silently ignored or missing values to fail only after a server round-trip, and returned a mutable parameter map.
  • Positional ? placeholder and comment scanning could miscount placeholders across PostgreSQL E'...' / e'...' escape strings, dollar-quote tag and identifier $ boundaries, nested block comments with adjacent delimiters (/*/*/ and */*), unterminated block comments, and bare \r line endings.

Solution

  • Validate non-null Dialect, sql, and values arguments in Statement.StatementFactory, check that the parsed ? placeholder count matches values.length before converting parameter values (throwing SpannerException with ErrorCode.INVALID_ARGUMENT on any mismatch, including when values are passed without ? placeholders), and return an unmodifiable parameter map.
  • Align client-side SQL lexical scanning for GoogleSQL and PostgreSQL across PostgreSQL escape string constants, dollar-quote tag and identifier boundaries, nested and unterminated block comments, and bare \r line endings in comments and single-line literals.

…ry.withUnnamedParameters

## Problem
- `Statement.StatementFactory.withUnnamedParameters(String, Object...)` did not validate that the number of provided parameter values matched the number of positional `?` placeholders in the SQL string, allowing extra values to be silently ignored or missing values to fail only after a server round-trip, and returned a mutable parameter map.
- Positional `?` placeholder and comment scanning could miscount placeholders across PostgreSQL `E'...'` / `e'...'` escape strings, dollar-quote tag and identifier `$` boundaries, nested block comments with adjacent delimiters (`/*/*/` and `*/*`), unterminated block comments, and bare `\r` line endings.

## Solution
- Validate non-null `Dialect`, `sql`, and `values` arguments in `Statement.StatementFactory`, check that the parsed `?` placeholder count matches `values.length` before converting parameter values (throwing `SpannerException` with `ErrorCode.INVALID_ARGUMENT` on any mismatch, including when values are passed without `?` placeholders), and return an unmodifiable parameter map.
- Align client-side SQL lexical scanning for GoogleSQL and PostgreSQL across PostgreSQL escape string constants, dollar-quote tag and identifier boundaries, nested and unterminated block comments, and bare `\r` line endings in comments and single-line literals.
@sakthivelmanii
sakthivelmanii requested review from a team as code owners November 18, 2026 21:50
@sakthivelmanii sakthivelmanii self-assigned this Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances SQL parsing and parameter validation in the Cloud Spanner Java client. It introduces strict validation in Statement.withUnnamedParameters to ensure the number of positional parameters matches the provided values, adds support for PostgreSQL escape string constants (E'...'), and improves the handling of carriage returns (\r), dollar-quoted string tags, and nested multi-line comments. Comprehensive unit tests have been added to verify these changes. No review comments were provided, so there is no additional feedback to address.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant